import 'dart:ui';

import 'package:flare_flutter/flare_actor.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_oa/route/routes.dart';
import 'package:shared_preferences/shared_preferences.dart';

class Splash extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => SplashState();
}

class SplashState extends State<Splash> {
  bool _snapToEnd = true;
  bool onbool = false;
  static const demoPlugin = const MethodChannel('demo.plugin');
  String countString = '';
  String localCount = '';

  _incrementCounter() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    setState(() {
      countString = countString + " 1";
    });
    int counter = (prefs.getInt('counter') ?? 0) + 1;
    await prefs.setInt('counter', counter);
  }

  _getCounter() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    setState(() {
      localCount = prefs.getInt('counter').toString();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Column(
        children: <Widget>[
          GestureDetector(
              onTap: () {
                setState(() {
                  _snapToEnd = false;
                });
              },
              child: SmileySwitch(
                onbool,
                snapToEnd: _snapToEnd,
                onToggle: () {
//          setState(() {
//            _snapToEnd = false;
//            onbool = !onbool;
//          });

                  String route = '${Routes.login}';
                  Routes.router.navigateTo(context, route,
                      replace: false, transition: TransitionType.fadeIn);
                },
              )),
          GestureDetector(
              onTap: () {
//                demoPlugin.invokeMethod('interaction');
                String route = '${Routes.googlemap}';
                Routes.router.navigateTo(context, route,
                    replace: false, transition: TransitionType.fadeIn);
              },
              child: Icon(
                Icons.keyboard,
                size: 55,
              )),
          Row(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              SizedBox(
                width: MediaQuery.of(context).size.width,
                height: 500,
                child: Text(
                  '222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222',
                  softWrap: true,
                  style: TextStyle(fontSize: 20,color: Colors.amber),
                ),
              ),
            ],
          )
        ],
      ),
    );
  }

  @override
  void initState() {
    super.initState();
    Future.delayed(Duration(seconds: 99999), () {
      String route = '${Routes.login}';
      Routes.router.navigateTo(context, route,
          replace: true, transition: TransitionType.fadeIn);
    });


  }
}

class SmileySwitch extends StatelessWidget {
  final bool isOn;
  final VoidCallback onToggle;
  final bool snapToEnd;

  SmileySwitch(this.isOn, {this.snapToEnd, this.onToggle});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        GestureDetector(
            onTap: onToggle,
            child: Container(
                width: 200,
                height: 100,
                child: FlareActor("animation/4.flr",
                    snapToEnd: snapToEnd, animation: isOn ? "On" : "Off"))),
      ],
    );
  }
}
